package org.vy.dal.dao;

import java.util.List;

import org.vy.dal.QueryManager;

public class VyPrintLabelGroupDAO {
	private static final String FIND_BY_GROUP_ID = "SELECT * FROM <TABLE> WHERE PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId";
	private static final String FIND_BY_VYID = "SELECT * FROM <TABLE> WHERE VY_ID = m_VyId";
	private static final String FIND_BY_SUBSCRIPTION_ID = "SELECT * FROM <TABLE> WHERE SUBSCRIPTION_ID = m_SubscriptionId";
	private static final String FIND_BY_GROUP_VY_ID = "SELECT * FROM <TABLE> WHERE VY_ID = m_VyId AND PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId";
	private static final String UPDATE = "UPDATE <TABLE> SET IS_LABEL_ADDRESS = m_IsLabelAddress WHERE PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId and SUBSCRIPTION_ID = m_SubscriptionId";
	private static final String INSERT = "INSERT INTO <TABLE> (PRINT_LABEL_GROUP_ID, SUBSCRIPTION_ID, VY_ID, IS_LABEL_ADDRESS) VALUES (m_PrintLabelGroupId, m_SubscriptionId, m_VyId, m_IsLabelAddress)";
	private static final String DELETE = "DELETE FROM <TABLE> WHERE PRINT_LABEL_GROUP_ID = m_PrintLabelGroupId and VY_ID = m_VyId and SUBSCRIPTION_ID = m_SubscriptionId";
	private static final String DELETE_BY_SUBSCRIPTION_ID = "DELETE FROM <TABLE> WHERE SUBSCRIPTION_ID = m_SubscriptionId";
	private static final String DELETE_BY_VY_ID = "DELETE FROM <TABLE> WHERE VY_ID = m_VyId";

	public static VyPrintLabelGroupDO findByPK(String groupId, String vyId)
			throws Exception {
		VyPrintLabelGroupDO dto = new VyPrintLabelGroupDO();
		dto.setPrintLabelGroupId(groupId);
		dto.setVyId(vyId);
		dto = (VyPrintLabelGroupDO) QueryManager.executeQuery(dto,
				FIND_BY_GROUP_VY_ID);
		return dto;
	}

	@SuppressWarnings("unchecked")
	public static List<VyPrintLabelGroupDO> findByVyId(String vyId)
			throws Exception {
		VyPrintLabelGroupDO dto = new VyPrintLabelGroupDO();
		dto.setVyId(vyId);
		return (List<VyPrintLabelGroupDO>) QueryManager.executeListQuery(dto,
				FIND_BY_VYID);
	}

	public static VyPrintLabelGroupDO findBySubscriptionId(String subId)
			throws Exception {
		VyPrintLabelGroupDO dto = new VyPrintLabelGroupDO();
		dto.setSubscriptionId(subId);
		return (VyPrintLabelGroupDO) QueryManager.executeQuery(dto,
				FIND_BY_SUBSCRIPTION_ID);
	}

	@SuppressWarnings("unchecked")
	public static List<VyPrintLabelGroupDO> findByGroupId(String groupId)
			throws Exception {
		VyPrintLabelGroupDO dto = new VyPrintLabelGroupDO();
		dto.setPrintLabelGroupId(groupId);
		return (List<VyPrintLabelGroupDO>) QueryManager.executeListQuery(dto,
				FIND_BY_GROUP_ID);
	}

	public static VyPrintLabelGroupDO insert(VyPrintLabelGroupDO dto)
			throws Exception {
		dto = (VyPrintLabelGroupDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyPrintLabelGroupDO update(VyPrintLabelGroupDO dto)
			throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static boolean delete(VyPrintLabelGroupDO dto) throws Exception {
		boolean i = QueryManager.executeDelete(dto, DELETE);
		return i;
	}

	public static boolean deleteByVyId(VyPrintLabelGroupDO dto)
			throws Exception {
		boolean i = QueryManager.executeDelete(dto, DELETE_BY_VY_ID);
		return i;
	}

	public static boolean deleteBySubscriptionId(VyPrintLabelGroupDO dto)
			throws Exception {
		boolean i = QueryManager.executeDelete(dto, DELETE_BY_SUBSCRIPTION_ID);
		return i;
	}
}
